﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Controller;

namespace IAI
{
    /// <summary>
    /// Interaction logic for NoteWindow.xaml
    /// </summary>
    public partial class NoteWindow : Window //Trang
    {
        public bool isClose = true;
        private MyController _myController;

        public NoteWindow(MyController myController)
        {
            InitializeComponent();
            _myController = myController;
            txtOldValue.IsReadOnly = true;
        }

        private void bntSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                isClose = false;
                this.Close();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
        private void bntClose_Click(object sender, RoutedEventArgs e)
        {
            isClose = true;
            this.Close();
        }
        private void txtNewValue_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            Regex regex = new Regex("^[0-9]+[.]{0,1}[0-9]*$"); //match real or decimal
            e.Handled = !regex.IsMatch((sender as TextBox).Text.Insert((sender as TextBox).SelectionStart, e.Text));
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if(Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.W))
                this.Close();
        }
    }
}
